package com.mybatis.main;

import com.mybatis.mapper.RoleMapper;
import com.mybatis.utils.SqlSessionFactoryUtils;
import java.util.Calendar;
import org.apache.ibatis.session.SqlSession;
import org.apache.log4j.Logger;

/**
 * @author qinjiasheng
 */
public class Chapter3Main {
	public static void main(String[] args) {
		Logger log = Logger.getLogger(Chapter3Main.class);
		SqlSession sqlSession = null;
		try {
			sqlSession = SqlSessionFactoryUtils.openSqlSession();
			RoleMapper roleMapper = sqlSession.getMapper(RoleMapper.class);
//			for (int i=1;i<50;i++) {
//				Role insertRole = new Role("roleName"+(i+1), "note"+(i+1));
//				roleMapper.insertRole(insertRole);
//			}
//			Role updateRole = new Role(5L, "roleNamekkkfff", "notefffkkkddf");
//			roleMapper.updateRole(updateRole);
//			Role _updateRole = roleMapper.getRole(5L);
//			log.info(_updateRole);
//			roleMapper.deleteRole(8L);
//			sqlSession.commit();
//			List<Role> roles = roleMapper.findRoles("roleName");
//			for (Role r : roles) {
//				log.info(r);
//			}
//			Role role = roleMapper.getRole(30L);
//			log.info(role.toString());
			Calendar now = Calendar.getInstance();
//			now.setTime(new Date());
			int week = now.get(Calendar.DAY_OF_WEEK);
			log.info("week======="+(week-1)%7);
			log.info("Year======="+now.get(Calendar.YEAR));
			log.info("Month======="+now.get(Calendar.MONTH));
			log.info("day======="+now.get(Calendar.DAY_OF_MONTH));
			log.info("hour======="+now.get(Calendar.HOUR_OF_DAY));
			log.info("min======="+now.get(Calendar.MINUTE));
			log.info("sec======="+now.get(Calendar.SECOND));
		}finally {
			if (sqlSession != null) {
				sqlSession.close();
			}
		}
	}
}
